<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Page;

class ArticleController extends CommonController {
    
	
	private function getcate(){
		$cate = M('Artcate');
		$catelist=$cate->getField('id,name');
		$this->assign('catelist',$catelist);
		
	}
	
	public function index(){

		$this->getcate();
		
		parent::index(true);
    }
    
	public function info(){

		$id=$_GET['id'];
		$m=M(CONTROLLER_NAME);
		$arr=$m->find($id);
		$this->assign('data',$arr);
		
		
		$this->display(CONTROLLER_NAME.'/info');
    }
    
		
	public function modify(){
			$this->getcate();
			
			parent::modify();
		}
		
		public function update(){
			$m=D('Article');
			
			$upload = new \Think\Upload();   
			$upload->maxSize   =     3145728 ;
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');
			$upload->savePath  =      '/images/'; 
			$info_logo   =   $upload->uploadOne($_FILES['logoimgpath']);
			if(!$info_logo) {// 上传错误提示错误信息
			     unset($_POST['logoimg']);
			}else{// 上传成功 获取上传文件信息
			    $_POST['logoimg'] = '/Uploads'.$info_logo['savepath'].$info_logo['savename'];
				$imginfo = $m-> where('id='.$_POST['id'])->getField('logoimg');
				
				//删除 原来的 图片 
				if(is_file($root.$imginfo)) {
					//echo "删除 员图片 ";
					unlink($root.$imginfo);
				}
			}
			
			if(!$m->create()){
				$this->show('error');
			}
			$idNum=$m->save();
			if($idNum>0){
				$this->show('ok');
			}else{
				$this->show('error');
			}
		}
		
		public function add(){
			$this->getcate();
			$this->display('Article/add');
		}
		
		public function create(){
			
			$upload = new \Think\Upload();   
			$upload->maxSize   =     3145728 ;
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');
			$upload->savePath  =      '/images/';
			// 上传文件 
			$info   =   $upload->uploadOne($_FILES['logoimgpath']);
			if(!$info) {// 上传错误提示错误信息
			    
			}else{// 上传成功 获取上传文件信息
			    $_POST['logoimg'] = '/Uploads'.$info['savepath'].$info['savename'];
			}
			
			$m=D('Article');
			if(!$m->create()){
				$this->show('error');
			}
			
			$idNum=$m->add();
			if($idNum>0){
				$this->show('ok');
			}else{
				$this->show('error');
			}
			
		}
		
		
    
}